import type { IndicatorInfo } from '@/types'
import { indicatorSubmitApi } from '@/api'

/** 数据存储为录入的统计指标 */
export function useEntryStatisticalndicators(
  needLoading: boolean = true,
) {
  const [loading, setLoading] = useState(false)
  const [lists, setLists] = useShallowState<
    IndicatorInfo[]
  >([])

  async function queryEntryIndicatorsByPointId(
    pointId: number,
  ) {
    needLoading && setLoading(true)
    try {
      const { data: res }
        = await indicatorSubmitApi.listIndicator(pointId)
      setLists(res)
    }
    catch (e) {
    }
    finally {
      needLoading && setLoading(false)
    }
  }

  return {
    /** 统计指标数据 */
    lists,
    setLists,

    /** 查用能单元下数据存储为录入的统计指标 */
    queryEntryIndicatorsByPointId,

    /** 加载中状态 */
    loading,
    setLoading,
  }
}
